import axios from 'axios'
import { Message } from 'element-ui'

const http = axios.create({
  baseURL: '',
  timeout: '60000',
  validateStatus(status) {
    return status >= 200 && status < 400
  }
})
http.interceptors.request.use((config) => {
  const token = localStorage.getItem('token')
  if (token) config.headers['authorzation'] = token
  return config
})
http.interceptors.response.use(
  (response) => {
    return response.data
  },
  (reason) => {
    Message.error('当前网络繁忙，请稍后再试~')
    return Promise.reject(reason)
  }
)
export default http
